const {DataTypes} = require('sequelize');
const seq = require('../db/seq');
const moment = require('moment');

//创建User模型

const Index = seq.define('user', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    username: {
        type: DataTypes.STRING
    },
    password: {
        type: DataTypes.STRING
    },
    siteId: {
        type: DataTypes.STRING
    },
    type: {
        type: DataTypes.INTEGER
    }
});

//创建Message模型
const Message = seq.define('message', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    fromUserId: {
        type: DataTypes.INTEGER
    },
    toUserId: {
        type: DataTypes.INTEGER
    },
    content: {
        type: DataTypes.STRING
    },
    isSend: {
        type: DataTypes.INTEGER
    },
    isRead: {
        type: DataTypes.INTEGER
    },
    createdAt: {
        type: DataTypes.DATE,
        get() {
            return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    }
});

//创建Site模型
const Site = seq.define('site', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    domain: {
        type: DataTypes.STRING
    },
    title: {
        type: DataTypes.STRING
    },
    color: {
        type: DataTypes.STRING
    },
    phone: {
        type: DataTypes.STRING
    },
    logo: {
        type: DataTypes.STRING
    },
    photo: {
        type: DataTypes.STRING
    },
    introduce: {
        type: DataTypes.STRING(1000)
    },
    token: {
        type: DataTypes.STRING
    },
    createdAt: {
        type: DataTypes.DATE,
        get() {
            return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm:ss');
        }
    }
});
// seq.sync({alter: true}).then(() => {
//
// });
module.exports = {
    User: Index,
    Message,
    Site
};
